//
//  PopUIManager.m
//  school
//
//  Created by ci123 on 15-3-20.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "PopUIManager.h"
#import "ScreenAdapter.h"


static PopUIManager * PopUIMgr;

@implementation PopUIManager

+ (PopUIManager *)getInstanse{
    if (PopUIMgr == nil) {
        PopUIMgr = [[PopUIManager alloc]init];
    }
    return PopUIMgr;
}

-(void)popAlertView:(id)super_view title:(NSString *)t message:(NSString *)m cancelButtonTitle:bt{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:t message:m delegate:super_view cancelButtonTitle:bt otherButtonTitles:nil];
    [alert show];
}

/**
 显示等待旋转模态层
 */				
- (void)showWaitingUI:(UIView *) super_view{
    [self removeWaitingUI];
    //添加遮罩层
    self.modalView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT)];
    self.modalView.layer.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor;
    
    //添加indicator（旋转加载）
    if (_indicator == nil) {
        self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    }
    self.indicator.frame = CGRectMake(0, 0, 80, 80);
    
    //设置显示位置
    [self.indicator setCenter:_modalView.center];
    //设置背景色
    self.indicator.backgroundColor = [UIColor grayColor];
    //设置背景透明
    self.indicator.alpha = 0.9;
    
    self.indicator.layer.cornerRadius = 6;
    self.indicator.layer.masksToBounds = YES;
    //将初始化好的indicator add到view中
    [self.modalView addSubview:self.indicator];
    
    //让等待层覆盖所有的层。
    UIWindow* currentWindow = [UIApplication sharedApplication].keyWindow;
    [currentWindow addSubview:self.modalView];
    
    [self.indicator startAnimating];
}

/**
 移除等待旋转模态层
 */
-(void)removeWaitingUI{
    if (self.modalView != nil) {
        [self.modalView removeFromSuperview];
        self.modalView = nil;
    }
    if (self.indicator != nil) {
        [self.indicator stopAnimating];
    }
    
}

@end
